import 'package:flutter/material.dart';

class ItemView extends StatelessWidget {
  final String? title;
  final Widget? leftWidget;
  final Widget? rightWidget;
  final double? width;            // 新增：整体宽度
  final double? height;           // 已有的高度参数，保留
  final double? leftPadding;      // 新增：左侧内容距左边的距离
  final double? rightPadding;     // 新增：右侧内容距右边的距离
  final double? lineMarginLeft;
  final double? lineMarginRight;
  final double? marginTop;
  final bool? showLine;
  final VoidCallback? onTap;
  final double? horizontalPadding;
  final double? borderRadius;
  final Color? backgroundColor;
  final AlignmentGeometry? alignment; // 新增：内容对齐方式

  const ItemView({
    Key? key,
    this.title,
    this.leftWidget,
    this.rightWidget,
    this.width,
    this.height,
    this.leftPadding = 15,        // 默认左侧边距
    this.rightPadding = 15,       // 默认右侧边距
    this.lineMarginLeft,
    this.lineMarginRight,
    this.marginTop,
    this.showLine,
    this.onTap,
    this.horizontalPadding = 15,
    this.borderRadius = 0,
    this.backgroundColor = Colors.white,
    this.alignment = Alignment.center, // 默认居中对齐
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Padding(
          padding: EdgeInsets.symmetric(
            horizontal: horizontalPadding ?? 15,
          ),
          child: GestureDetector(
            onTap: onTap,
            child: Container(
              width: width, // 设置整体宽度
              margin: EdgeInsets.only(top: marginTop ?? 0),
              decoration: BoxDecoration(
                color: backgroundColor,
                borderRadius: BorderRadius.circular(borderRadius ?? 0),
              ),
              height: height ?? 48,
              alignment: alignment, // 设置内容对齐方式
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Padding(
                    padding: EdgeInsets.only(left: leftPadding ?? 15),
                    child: leftWidget ??
                        Row(
                          children: [
                            Text(
                              title ?? "",
                              style: const TextStyle(
                                color: Color(0xFF333333),
                                fontSize: 14,
                              ),
                            ),
                          ],
                        ),
                  ),

                  Padding(
                    padding: EdgeInsets.only(right: rightPadding ?? 15),
                    child: rightWidget ??
                        const Icon(
                          Icons.arrow_forward_ios,
                          color: Colors.grey,
                          size: 14,
                        ),
                  ),
                ],
              ),
            ),
          ),
        ),
        if (showLine ?? false)
          Container(
            margin: EdgeInsets.only(
              left: (horizontalPadding ?? 15) + (lineMarginLeft ?? 0),
              right: (horizontalPadding ?? 15) + (lineMarginRight ?? 0),
            ),
            child: const Divider(
              color: Color(0xF2F2F4EE),
              height: 0.3,
            ),
          ),
      ],
    );
  }
}